package fy.hr.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.requester.IServiceRequester;
import com.soa.eis.adapter.framework.requester.impl.BaseServiceRequester;
import fy.hr.bean.PersonInfoBean;

public class FindPersonInfoDao3 {
	private String[] codes;
	IMsgObject respMo = null;
	private boolean needTime = false;
	private boolean newAway = false;
	private static Log log = LogFactory.getLog(FindPersonInfoDao3.class);

	public JSONObject findPersonInfo() throws Exception {
		try {
			JSONObject jo = new JSONObject();
			// 获取服务调用者实例
		for (int i = 0, length = this.codes.length; i < length; i++) {
				IServiceRequester Requester = BaseServiceRequester.getInstance();
				IMsgObject reqMo = MqReqXml.add("06004", "06003000000008", codes[i]);
				respMo = Requester.execute(reqMo);
				log.info("respMo:" + respMo);
				//System.out.println("111" + respMo);
				List<GroupRecord> record2 = respMo.getResGroupRecord("return");
				for (GroupRecord groupRecord : record2) {
					String pk_tbm_psndoc = groupRecord.getFieldValue("pk_tbm_psndoc");
					if (groupRecord.getFieldValue("psncode") == null) {
					} else {
						PersonInfoBean pib = new PersonInfoBean();
						pib.setCode(groupRecord.getFieldValue("psncode"));
						pib.setName(groupRecord.getFieldValue("psnname"));
						pib.setDep(groupRecord.getFieldValue("deptname"));
						pib.setPost(groupRecord.getFieldValue("jobname"));
						pib.setExistPk_tbm_psndoc((pk_tbm_psndoc == null || "".equals(pk_tbm_psndoc) ? false : true));
						pib.setPk_corp(groupRecord.getFieldValue("pk_corp"));
						if (this.needTime) {
							pib.setDate(groupRecord.getFieldValue("basgroupdef4"));
						}
						if (this.newAway) {
							pib.setBasgroupdef23(groupRecord.getFieldValue("basgroupdef23"));
							pib.setId(groupRecord.getFieldValue("id"));
							if (i == 0) {
								pib.setMobile(groupRecord.getFieldValue("mobile"));
							}
						}
						jo.put(pib.getID(), pib.getJSONObject());
					}
				}
			}
			// list 转jsonboject
			return jo;
		} catch (Exception e) {
			log.error("******************************AAAAAAAAAAAAAAAAAAAAAAAAAAAAAa", e);
		}
		return null;
	}
	public void setCodes(String[] codesArray) {
		this.codes = codesArray;
	}
	public void setNeedTime(boolean needTime) {
		this.needTime = needTime;
	}
	public void setNewAway(boolean newAway) {
		this.newAway = newAway;
	}
}
